//2009/08/29 23:40:35
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class GymTraining
{
public:
    int trainingTime(int needToTrain, int minPulse, int maxPulse, int trainChange, int restChange)
    {
		int ret = 0;
		int pulse = minPulse;
		while(needToTrain > 0)
		{
			if(minPulse + trainChange > maxPulse) return -1;
			if(pulse + trainChange <= maxPulse)
			{
				needToTrain--;
				pulse += trainChange;
				cout << "train: " << pulse << endl;
			}
			else
			{
				pulse -= restChange;
				pulse = max(minPulse, pulse);
				cout << "rest: " << pulse << endl;
			}
			ret++;
		}
		return ret;
    }
};
